<template>
    <div>
        <el-dialog :title="myDialog.title" :visible.sync="myDialog.flag" width="70%">
            <el-form :model="addUser">
                {{addUser}}
                <el-form-item label="用户名" label-width="80px">
                    <el-input v-model="addUser.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" label-width="80px">
                    <el-input v-model="addUser.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="邮箱" label-width="80px">
                    <el-input v-model="addUser.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="电话" label-width="80px">
                    <el-input v-model="addUser.mobile" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="myDialog.flag = false">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import addUser from '@/utils/userApi/userAddApi'
import editUser from '@/utils/userApi/userEditApi'
export default {
    props: {
        myDialog: Object,
        addUser: Object,
        editId:Number
    },
    methods: {
        async submit() {
            if (this.myDialog.type == 'add') {
                // alert(111)
                let res = await addUser(this.addUser);
                if(res.meta.status == 201) {
                    this.$message.success(res.meta.msg);
                    this.$emit('Update');
                    this.close();
                } 
            } else if (this.myDialog.type == 'edit') {
                let res = await editUser(this.editId);
                this.$message.success(res.meta.msg);
                this.$emit('Update');
                this.close();
            }
        },
        close() {
            this.myDialog.flag = false;
        }
    }
}
</script>

<style lang="scss" scoped>

</style>